package day0314;

import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class ClientDemo {
    private Socket socket;

    public ClientDemo() {
        try {
            System.out.println("建立客户端");
            socket =new Socket("176.117.102.130",8800);
            System.out.println("建立完毕");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public void start(){

        try {
            OutputStream os =socket.getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(os, StandardCharsets.UTF_8);
            BufferedWriter bw =new BufferedWriter(osw);
            PrintWriter pw =new PrintWriter(osw,true);
            Scanner scan = new Scanner(System.in);
            String line=scan.nextLine();
            while (!"exit".equalsIgnoreCase(line)){
                pw.println(line);
                line = scan.nextLine();
            }


        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }

    public static void main(String[] args) {
        ClientDemo client = new ClientDemo();
        client.start();
    }
}
